#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
 main() {
 struct stat buf;
struct tm * atime;
struct tm * mtime;
struct tm * ctime;
 stat("/etc/passwd", &buf);
 atime = localtime ( &buf.st_atime);  
 mtime = localtime ( &buf.st_mtime); 
 ctime = localtime ( &buf.st_ctime); 
printf("file:  /etc/passwd\n");
 printf("file size = %ld \n", buf.st_size);//total size, in bytes 文件大小, 以字节计算 
 printf("device file num = %ld \n", buf.st_dev); //device 文件的设备编号
 printf("inode file i-node = %ld \n", buf.st_ino);  //inode 文件的i-node
 printf("protection file type & authority = %d\n", buf.st_mode); //protection 文件的类型和存取的权限
 printf("number of hard links = %ld \n", buf.st_nlink); //number of hard links 连到该文件的硬连接数目, 刚建立的文件值为1.
  printf("user ID of owner = %d \n", buf.st_uid); //user ID of owner 文件所有者的用户识别码 
  printf("group ID of owner = %d \n", buf.st_gid); //group ID of owner 文件所有者的组识别码
  printf("divice type = %ld \n", buf.st_rdev); //device type 若此文件为装置设备文件, 则为其设备编号 
  printf("blocksize for filesystem I/O = %ld \n", buf.st_blksize); //blocksize for filesystem I/O 文件系统的I/O 缓冲区大小. 
  printf("number of blocks allocated = %ld \n", buf.st_blocks); //number of blocks allocated 占用文件区块的个数, 每一区块大小为512 个字节. 
  printf("time of lastaccess = %s \n", asctime(atime)); //time of lastaccess 文件最近一次被存取或被执行的时间, 一般只有在用mknod、 utime、read、write 与tructate 时改变.
  printf("time of last modification = %s \n", asctime(mtime)); //time of last modification 文件最后一次被修改的时间, 一般只有在用mknod、 utime 和write 时才会改变
  printf("time of last change i-noder = %s \n", asctime(ctime)); //time of last change i-node 最近一次被更改的时间, 此参数会在文件所有者、组、 权限被更改时更新 
}